<?php
class contrl_site extends contrl_admin{
	 function __construct(&$db,&$view,&$model,&$config,&$routes){
     $this->view=&$view;
     $this->model=&$model;
     $this->config=&$config;
     $this->db=&$db;
     $this->url=array();
     $this->routes=&$routes;
    }

    function standby(){        $tmp=$this->model->return_task("standby",$this->template[0]['id']);        foreach($tmp as $key=>$value){         if($this->side[$value['side']]){
          $tmp=call_user_func(array($this->_load_module($value['class']),"_".$value['name']."_standby"),$value['side']);
          if($tmp !="" || count($tmp) !=0){
          $data[$value['side']]=$tmp;
           }else{           	$tmp[$value['class']."_info"]="Not active or service";
            }
         }
       }
       if($data=="")$data['standby_modules']="Not find modules";
       return $data;
    }

    function schedule($url){      if(!empty($url)){       array_unshift($url,"side");       $tmp=$this->model->return_task("schedule",$this->template[0]['id']);
       foreach($tmp as $key=>$value){       	if($this->side[$value['side']]){           $url[0]=$value['side'];
           $tmp=call_user_func_array(array($this->_load_module($value['class']),"_".$value['name']."_schedule"),array_slice($url,0));
            if($tmp !="" || count($tmp) !=0){            	$data[$value['side']]=$tmp;
             }else{              $tmp[$value['class']."_info"]="Not active or service";
              }
              };
        }
      if($data=="")$data['schedule_modules']="Not find modules";       return $data;
       }else{       	 $data['schedule_modules']="Url empty";
        return $data;
       }
    }

    function events($arg=true){     $this->_call_out_func("lang","default_lang");     $this->_call_out_func("user_auth","default_user");
     $this->lang=$this->_call_out_func("lang","get_message_module");
     $this->view->set_lang($this->lang);     if(empty($_SERVER['REDIRECT_URL'])){     	 $this->choice_template($url);     	 return $this->standby();
			}else{
			 $url=$this->analysis_url(SITE_URL,$_SERVER['REDIRECT_URL']);
			 if($url[0]=='/') $url=substr($url, 1);
			 $url=$this->route($url);
			 if($url[strlen($url)-1]=='/') $url=substr($url, 0, -1);
			 $url=explode('/', $url);
    		 $count=(count($url)-1);
			 for($i=0;$i<=$count;$i++)$url[$i]= $this->security($url[$i]);
			  $url=$this->direct_link($url);
                 $this->url=$url;
                 $this->choice_template($url);
               	 if($url[0]==ADMIN_DIR){
                   $this->start_admin();
                   return "admin_mode";
               	 	 }else{               	 $tmp=$this->model->return_task("events",$this->template[0]['id']);
               	 foreach($tmp as $key=>$value){               	  if($url[0]==$value['class'])$class=$this->_load_module($url[0]);
               	 }

               	 if (isset($class)){
               	 	if (!isset ($url[1])) $url[1]=START_FUNC_NAME;
             	  $tmp=call_user_func_array(array($class,$url[1]),array_slice($url,2));
             	  if($tmp !="" || count($tmp) !=0){             	  	$data=$tmp;

          			}else{
           				$data[$url[1]."_info"]="Not active";
           			}
           	      $this->contrl_side($data);
             	  return $data;


             	 };
             	 $this->show_404 ();
                }

			}
          }


	function core(){		session_start();        $this->start_time();

     	$data_events=$this->events();
     	if($data_events !="admin_mode"){
	     $data_schedule=$this->schedule($this->url);
         $data=$data_events+$data_schedule;
         $this->view->view($this->template[0] ['path_file'], $data);
        }
        echo "<br><div style='margin-top:30px;clear:both;padding:10px;border:1px solid;float:left'>".$this->end_time()."</div>";
   	}




}

?>
